import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export const schoolResolvers = {
    query: {
        schools: async () => {
            return prisma.school.findMany({
                include: { users: true },
            });
        },
        school: async (_: any, { id }: { id: string }) => {
            return prisma.school.findUnique({
                where: { id },
                include: { users: true },
            });
        },
    },
    mutation: {
        createSchool: async (_: any, { name }: { name: string }) => {
            // Ensure Prisma Client is up-to-date with the schema
            return prisma.school.create({
                data: { name },
                include: { users: true },
            });
        },
        updateSchool: async (_: any, { id, name }: { id: string, name: string }) => {
            return prisma.school.update({
                where: { id },
                data: { name },
                include: { users: true },
            });
        },
        deleteSchool: async (_: any, { id }: { id: string }) => {
            return prisma.school.delete({
                where: { id },
                include: { users: true },
            });
        },
    },
    join: {
        User: {
            school: async (_: { schoolId: string | null }) => {

                if (!_.schoolId) {
                    return null;
                }
                return prisma.school.findUnique({
                    where: { id: _.schoolId },
                });
            },
        }
    }

}
